package com.py.credit.controller;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.entity.GatewayUserEntity;
import com.py.credit.entity.SysMsgDetailEntity;
import com.py.credit.entity.SysMsgEntity;
import com.py.credit.entity.SysUser;
import com.py.credit.entity.common.OptionalColumn;
import com.py.credit.entity.enums.UserManagerZREnum;
import com.py.credit.entity.enums.UserMangerEnum;
import com.py.credit.service.CardsService;
import com.py.credit.service.GatewayAuthenticationService;
import com.py.credit.service.GatewayUserService;
import com.py.credit.service.MsgService;
import com.py.credit.service.XypjRemoteBaseService;
import com.py.credit.service.UserManagerService;
import com.py.credit.utils.EmailUtil;
import com.py.credit.utils.ExcelUtil;
import com.py.credit.utils.MapCache;
import com.py.framework.core.annotation.IgnoreAuthority;
import com.py.framework.core.common.Page;
import com.py.framework.core.controller.BaseController;
import com.py.framework.core.entity.SysUserEntity;
import com.py.framework.core.helper.HttpServletHelper;

@RestController
@RequestMapping(value = "/userManager")
public class UserManagerController extends BaseController {
	private static final String USER_MANAGER = "user_manger";

	private static final String USER_MANAGER_ZR = "user_manger_zr";
	@Autowired
	private XypjRemoteBaseService xypjRemoteBaseService;
	@Autowired
	private UserManagerService userManagerService;
	@Autowired
	private MsgService msgService;
	@Value("${platformUrl}")
	private String Eurl;

	@Autowired
	private GatewayAuthenticationService gatewayAuthenticationService;

	@Autowired
	private GatewayUserService gatewayUserService;

	@Autowired
	private CardsService cardsService;
	@Value("${pdfPagePath}")
	private String url;

	@RequestMapping(value = "/getCountColums.json")
	public RestServiceResult<List<OptionalColumn>> getCountColums() {
		return new RestServiceResult<List<OptionalColumn>>(UserMangerEnum.getOptionalColumns());
	}

	@RequestMapping(value = "/getDefaultCountColums.json")
	public RestServiceResult<List<String>> getDefaultCountColums() {
		return new RestServiceResult<List<String>>(UserMangerEnum.getDefaultShowColumnEN());
	}

	@RequestMapping(value = "/getAdvancedCountColums.json")
	public RestServiceResult<List<OptionalColumn>> getAdvancedCountColums() {
		return new RestServiceResult<List<OptionalColumn>>(UserMangerEnum.getAdvancedConditionColumns());
	}

	@RequestMapping(value = "/addShowColunms.json")
	public RestServiceResult<String> addShowColunms(@RequestParam(value = "columns", required = true) String[] columns,
			HttpServletRequest request) {
		RestServiceResult<String> result = new RestServiceResult<String>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("AchievementController#addShowColunms", "未获取到当前用户信息！");
				return result;
			}
			String column = StringUtils.join(columns, ",");
			MapCache.set(userInfo.getId() + "_" + USER_MANAGER, StringUtils.split(column, ","));
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		return new RestServiceResult<String>();
	}

	@RequestMapping(value = "/export.json")
	public RestServiceResult<List<Map<String, Object>>> exportData(
			@RequestParam(value = "type", required = true) String type,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition,
			@RequestParam(value = "columnEN", defaultValue = "", required = true) String columnEN, Page page,
			HttpServletResponse response, HttpServletRequest request) {
		page.setLimit(1000);
		List<String> showColumns = JSONArray.parseArray(columnEN, String.class);
		List<OptionalColumn> optionalColumns = UserMangerEnum.getOptionalColumns();
		List<Map<String, Object>> data;
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("userManager#getAchievementCount", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		try {
			data = userManagerService.selectAllUserInfromationForPage(type, showColumns, null, condition, page);
			if (RestServiceResult.CODE_SUCCESS != result.getCode()) {
				return result;
			}
			ExcelUtil.downloadExcel(response, data, "用户信息列表", "用户信息列表", showColumns, optionalColumns);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("用户信息列表导出异常，请稍后再试！");
			ExceptionLogger.error("用户信息列表导出异常！", e.getMessage(), e);
			return result;
		}
	}

	@RequestMapping(value = "/userManagerInformation.json")
	public RestServiceResult<List<Map<String, Object>>> UserManagerInformation(
			@RequestParam(value = "type", required = true) String type,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition, Page page,
			HttpServletRequest request) {
		RestServiceResult<List<Map<String, Object>>> r = new RestServiceResult<List<Map<String, Object>>>();
		List<Map<String, Object>> userList = new ArrayList<Map<String, Object>>();
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				r.setCode(RestServiceResult.CODE_UNKNOW);
				r.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("userManager#getAchievementCount", "未获取到当前用户信息！");
				return r;
			}
		} else {
			r.setCode(user.getCode());
			r.setMsg(user.getMsg());
			return r;
		}
		String[] configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + USER_MANAGER);
		List<String> showColumns = (configColumns == null || configColumns.length == 0)
				? UserMangerEnum.getDefaultShowColumnEN() : Arrays.asList(configColumns);
		List<Map<String, Object>> data;
		try {
			userList = userManagerService.selectAllUserInfromationForPage(type, showColumns, new String[] { "id" },
					condition, page);
			r.setCount(page.getTotalCount());
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg(e.getMessage());
			ExceptionLogger.error("userManager#userManagerInformation", "用户信息列表查询失败");
		}
		r.setData(userList);
		return r;
	}

	@RequestMapping(value = "/updateFreeUnlockStatus.json")
	public RestServiceResult updateFreeUnlockStatus(@RequestParam(value = "zhzt", required = true) String zhzt,
			@RequestParam(value = "id", required = true) String id) {
		RestServiceResult rest = new RestServiceResult();
		try {
			if (!StringUtils.isEmpty(id)) {
				userManagerService.updateFreeUnlockStatus(zhzt, Integer.valueOf(id));
				rest.setMsg("修改成功");
			}

			if ("D".equals(zhzt)) {
				Map<String, Object> userInformation = userManagerService.selectOneUserInformation(Integer.parseInt(id));
				gatewayAuthenticationService.clearUserSessionAllToken(userInformation.get("username") + id);
			}
		} catch (Exception e) {
			rest.setCode(RestServiceResult.CODE_UNKNOW);
			rest.setMsg("修改失败");
			ExceptionLogger.error("userManager#updateFreeUnlockStatus", "用户状态修改失败");
		}
		return rest;
	}

	@RequestMapping(value = "/updateUserPassword.json")
	public RestServiceResult updateUserPassword(@RequestParam(value = "password", required = true) String password,
			@RequestParam(value = "id", required = true) String id) {
		RestServiceResult rest = new RestServiceResult();
		try {
			if (!StringUtils.isEmpty(id)) {
				userManagerService.updateUserPassword(password, Integer.valueOf(id));
				rest.setMsg("密码修改成功");
			}

			Map<String, Object> userInformation = userManagerService.selectOneUserInformation(Integer.parseInt(id));
			gatewayAuthenticationService.clearUserSessionAllToken(userInformation.get("username") + id);
		} catch (Exception e) {
			rest.setCode(RestServiceResult.CODE_UNKNOW);
			rest.setMsg("密码修改失败");
			ExceptionLogger.error("userManager#updateUserPassword", "用户密码修改失败");
		}
		return rest;
	}

	@RequestMapping(value = "/selectOneUserInformation.json")
	public RestServiceResult<Map<String, Object>> selectOneUserInformation(
			@RequestParam(value = "id", required = true) String id) {
		RestServiceResult<Map<String, Object>> userRest = new RestServiceResult<Map<String, Object>>();
		Map<String, Object> userList = new HashMap<String, Object>();
		try {
			if (!StringUtils.isEmpty(id)) {
				userList = userManagerService.selectOneUserInformation(Integer.valueOf(id));
			}
		} catch (Exception e) {
			userRest.setCode(RestServiceResult.CODE_UNKNOW);
			userRest.setMsg("查询失败");
			ExceptionLogger.error("userManager#selectOneUserInformation", "用户信息查失败");
		}
		userRest.setData(userList);
		return userRest;
	}

	@IgnoreAuthority
	@RequestMapping(value = "/updateUserShzt.json")
	public RestServiceResult updateUserShzt(@RequestParam(value = "userid", required = true) String userid,
			@RequestParam(value = "shzt", required = true) String shzt,
			@RequestParam(value = "shyj", required = true) String shyj, HttpServletRequest request) {
		RestServiceResult rest = new RestServiceResult();
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				rest.setCode(RestServiceResult.CODE_UNKNOW);
				rest.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("AchievementController#getAchievementCount", "未获取到当前用户信息！");
				return rest;
			}
		} else {
			rest.setCode(user.getCode());
			rest.setMsg(user.getMsg());
			return rest;
		}
		try {
			userManagerService.updateUserShzt(shzt, shyj, String.valueOf(userInfo.getId()), userid);
			if (shzt.equals("T")) {
				cardsService.updateCardStatus(userid);
			}
			String[] type = { "SF", "SS", "ZZ" };
			List<String> list = new ArrayList<>();
			for (int i = 0; i < type.length; i++) {
				List<String> list1 = cardsService.selectCardIdByUserId(userid, type[i]);
				if (!list1.isEmpty()) {
					list.add(list1.get(0));
				}
			}
			String shzt1 = "";
			if (shzt.equals("T")) {
				shzt1 = "1";
			}
			if (!shzt.equals("T")) {
				shzt1 = "2";
			}
			for (int i = 0; i < list.size(); i++) {
				cardsService.updateCardShzjByUserId(list.get(i), shzt1);
				cardsService.addHistory(userInfo.getUsername(), shyj, Long.parseLong(list.get(i)), shzt1, "实名认证中心");
			}
			rest.setMsg("用户审核成功");

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("id", Long.parseLong(userid));
			GatewayUserEntity gatewayUserEntity = gatewayUserService.getUserByTwoPrincipal(params);
			gatewayAuthenticationService.refreshUserSessionAllToken(gatewayUserEntity);
			String userType = "";
			if (gatewayUserEntity.getType().equals("C")) {
				userType = "企业";
			}
			if (gatewayUserEntity.getType().equals("P")) {
				userType = "个人";
			}
			if (shzt.equals("T")) {
				Map<String, Object> model = new HashMap<String, Object>();
				model.put("userType", userType);
				model.put("hello", "恭喜您！");
				model.put("userName", gatewayUserEntity.getUsername());
				model.put("status", "通过");
				model.put("url", Eurl);
				EmailUtil.sendHtmlMessageByTemplate(gatewayUserEntity.getDzyx(), "【大数据征信】用户实名注册审核", model,
						"nameAuthenticationTemplate.ftl");
				SysMsgEntity entity = new SysMsgEntity();
				List<SysMsgDetailEntity> detail = new ArrayList<>();
				SysMsgDetailEntity entity1 = new SysMsgDetailEntity();
				detail.add(entity1);
				entity1.setRevieverName(gatewayUserEntity.getUsername());
				entity1.setReviever(gatewayUserEntity.getId());
				entity1.setRevieveType(1);
				entity.setMsgTitle("实名认证审核通知");
				entity.setMsgContent("【大数据征信平台】您的实名认证申请审核已通过，现在你可以放心使用更多服务");
				entity.setLinkUrl(Eurl);
				entity.setMsgType(1);
				entity.setDetails(detail);
				msgService.addMsgInfo(entity);
			}
			if (!shzt.equals("T")) {
				Map<String, Object> model = new HashMap<String, Object>();
				model.put("userType", userType);
				model.put("hello", "很抱歉，");
				model.put("userName", gatewayUserEntity.getUsername());
				model.put("status", "未通过");
				model.put("url", Eurl);
				EmailUtil.sendHtmlMessageByTemplate(gatewayUserEntity.getDzyx(), "【大数据征信】用户实名注册审核", model,
						"nameAuthenticationTemplate.ftl");
				SysMsgEntity entity = new SysMsgEntity();
				List<SysMsgDetailEntity> detail = new ArrayList<>();
				SysMsgDetailEntity entity1 = new SysMsgDetailEntity();
				detail.add(entity1);
				entity1.setRevieverName(gatewayUserEntity.getUsername());
				entity1.setReviever(gatewayUserEntity.getId());
				entity1.setRevieveType(1);
				entity.setMsgTitle("实名认证审核通知");
				entity.setMsgContent("您的实名认证申请审核未通过，请至个人中心实名认证再次发起申请，否则将影响你的正常服务使用");
				entity.setLinkUrl(Eurl);
				entity.setMsgType(1);
				entity.setDetails(detail);
				msgService.addMsgInfo(entity);
			}
		} catch (Exception e) {
			rest.setCode(RestServiceResult.CODE_UNKNOW);
			rest.setMsg("用户审核记录失败");
			ExceptionLogger.error("userManager#insertXypjUserCheck", "用户审核失败");
		}
		return rest;
	}

	@RequestMapping(value = "/selectUserCheck.json")
	public RestServiceResult<List<Map<String, String>>> selectUserCheck(
			@RequestParam(value = "userid", required = true) String userid, HttpServletRequest request) {
		RestServiceResult<List<Map<String, String>>> userRest = new RestServiceResult<List<Map<String, String>>>();
		List<Map<String, String>> userList = new ArrayList<Map<String, String>>();
		List<Map<String, String>> userNewList = new ArrayList<Map<String, String>>();
		String token = HttpServletHelper.getUserToken(request);
		Set<Integer> idset = new HashSet<Integer>();
		int id = 0;
		try {
			userList = userManagerService.selectUserCheck(userid);
			for (Map<String, String> map : userList) {
				id = Integer.valueOf(map.get("shuser"));
				idset.add(id);
				RestServiceResult<List<SysUserEntity>> user = xypjRemoteBaseService.getUsersByIds(idset, token);
				List<SysUserEntity> sysList = user.getData();
				for (SysUserEntity sysuser : sysList) {
					map.put("realName", sysuser.getRealName());
				}
				userNewList.add(map);
			}
		} catch (Exception e) {
			userRest.setCode(RestServiceResult.CODE_UNKNOW);
			userRest.setMsg("查询失败");
			ExceptionLogger.error("userManager#selectUserCheck", "用户审核记录查失败");
		}
		userRest.setData(userNewList);
		return userRest;
	}

	@RequestMapping("/getZjwj.json")
	public void getZjwj(@RequestParam(value = "id", defaultValue = "", required = true) String id,
			HttpServletResponse response) throws IOException {
		if (null != id && !"".equals(id)) {
			response.setContentType("image/png");
			response.setCharacterEncoding("UTF-8");
			OutputStream outputSream = response.getOutputStream();
			Map<String, Object> userInfo = new HashMap<String, Object>();
			userInfo = userManagerService.selectOneUserInformation(Integer.valueOf(id));

			InputStream fileInputStream = new FileInputStream((String) userInfo.get("zjwjurl"));
			byte[] data = this.toByteArray(fileInputStream);
			fileInputStream.close();

			InputStream in = new ByteArrayInputStream(data);
			in.close();
			int len = 0;

			byte[] buf = new byte[1024];
			while ((len = in.read(buf, 0, 1024)) != -1) {
				outputSream.write(buf, 0, len);
			}

			outputSream.close();
		}
	}

	private byte[] toByteArray(InputStream in) throws IOException {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024 * 4];
		int n = 0;
		while ((n = in.read(buffer)) != -1) {
			out.write(buffer, 0, n);
		}
		return out.toByteArray();
	}

	@RequestMapping("/getSfzwjFont.json")
	public void getSfzwjFont(@RequestParam(value = "id", defaultValue = "", required = true) String id,
			HttpServletResponse response) throws IOException {
		if (null != id && !"".equals(id)) {
			response.setContentType("image/png");
			response.setCharacterEncoding("UTF-8");
			OutputStream outputSream = response.getOutputStream();
			Map<String, Object> userInfo = new HashMap<String, Object>();
			userInfo = userManagerService.selectOneUserInformation(Integer.valueOf(id));

			InputStream fileInputStream = new FileInputStream((String) userInfo.get("sfzwj_frontUrl"));
			byte[] data = this.toByteArray(fileInputStream);
			fileInputStream.close();

			InputStream in = new ByteArrayInputStream(data);
			in.close();
			int len = 0;

			byte[] buf = new byte[1024];
			while ((len = in.read(buf, 0, 1024)) != -1) {
				outputSream.write(buf, 0, len);
			}

			outputSream.close();
		}
	}

	@RequestMapping("/getSfzwjBack.json")
	public void getSfzwjBack(@RequestParam(value = "id", defaultValue = "", required = true) String id,
			HttpServletResponse response) throws IOException {
		if (null != id && !"".equals(id)) {
			response.setContentType("image/png");
			response.setCharacterEncoding("UTF-8");
			OutputStream outputSream = response.getOutputStream();
			Map<String, Object> userInfo = new HashMap<String, Object>();
			userInfo = userManagerService.selectOneUserInformation(Integer.valueOf(id));

			InputStream fileInputStream = new FileInputStream((String) userInfo.get("sfzwj_backUrl"));
			byte[] data = this.toByteArray(fileInputStream);
			fileInputStream.close();

			InputStream in = new ByteArrayInputStream(data);
			in.close();
			int len = 0;

			byte[] buf = new byte[1024];
			while ((len = in.read(buf, 0, 1024)) != -1) {
				outputSream.write(buf, 0, len);
			}

			outputSream.close();
		}
	}

	// 自然人
	@RequestMapping(value = "/getZRCountColums.json")
	public RestServiceResult<List<OptionalColumn>> getZRCountColums() {
		return new RestServiceResult<List<OptionalColumn>>(UserManagerZREnum.getOptionalColumns());
	}

	@RequestMapping(value = "/getZRDefaultCountColums.json")
	public RestServiceResult<List<String>> getZRDefaultCountColums() {
		return new RestServiceResult<List<String>>(UserManagerZREnum.getDefaultShowColumnEN());
	}

	@RequestMapping(value = "/getZRAdvancedCountColums.json")
	public RestServiceResult<List<OptionalColumn>> getZRAdvancedCountColums() {
		return new RestServiceResult<List<OptionalColumn>>(UserManagerZREnum.getAdvancedConditionColumns());
	}

	@RequestMapping(value = "/addZRShowColunms.json")
	public RestServiceResult<String> addZRShowColunms(
			@RequestParam(value = "columns", required = true) String[] columns, HttpServletRequest request) {
		RestServiceResult<String> result = new RestServiceResult<String>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("AchievementController#addZRShowColunms", "未获取到当前用户信息！");
				return result;
			}
			String column = StringUtils.join(columns, ",");
			MapCache.set(userInfo.getId() + "_" + USER_MANAGER_ZR, StringUtils.split(column, ","));
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		return new RestServiceResult<String>();
	}

	@RequestMapping(value = "/ZRexport.json")
	public RestServiceResult<List<Map<String, Object>>> ZRexportData(
			@RequestParam(value = "type", required = true) String type,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition,
			@RequestParam(value = "columnEN", defaultValue = "", required = true) String columnEN, Page page,
			HttpServletResponse response, HttpServletRequest request) {
		page.setLimit(1000);
		List<String> showColumns = JSONArray.parseArray(columnEN, String.class);
		List<OptionalColumn> optionalColumns = UserManagerZREnum.getOptionalColumns();
		List<Map<String, Object>> data;
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("userManager#getAchievementCount", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		try {
			data = userManagerService.selectAllUserInfromationForPage(type, showColumns, null, condition, page);
			if (RestServiceResult.CODE_SUCCESS != result.getCode()) {
				return result;
			}
			ExcelUtil.downloadExcel(response, data, "自然人信息列表", "自然人信息列表", showColumns, optionalColumns);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("自然人信息列表导出异常，请稍后再试！");
			ExceptionLogger.error("自然人信息列表导出异常！", e.getMessage(), e);
			return result;
		}
	}

	@RequestMapping(value = "/zruserManagerInformation.json")
	public RestServiceResult<List<Map<String, Object>>> ZRUserManagerInformation(
			@RequestParam(value = "type", required = true) String type,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition, Page page,
			HttpServletRequest request) {
		RestServiceResult<List<Map<String, Object>>> r = new RestServiceResult<List<Map<String, Object>>>();
		List<Map<String, Object>> userList = new ArrayList<Map<String, Object>>();
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				r.setCode(RestServiceResult.CODE_UNKNOW);
				r.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("userManager#getAchievementCount", "未获取到当前用户信息！");
				return r;
			}
		} else {
			r.setCode(user.getCode());
			r.setMsg(user.getMsg());
			return r;
		}
		String[] configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + USER_MANAGER_ZR);
		List<String> showColumns = (configColumns == null || configColumns.length == 0)
				? UserManagerZREnum.getDefaultShowColumnEN() : Arrays.asList(configColumns);
		List<Map<String, Object>> data;
		try {
			userList = userManagerService.selectAllUserInfromationForPage(type, showColumns, new String[] { "id" },
					condition, page);
			r.setCount(page.getTotalCount());
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg(e.getMessage());
			ExceptionLogger.error("userManager#ZRUserManagerInformation", "自然人信息列表查询失败");
		}
		r.setData(userList);
		return r;
	}
}
